package top.canyue.eca_manager;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author canyue
 * @version 1.0
 * &#064;date  2024/3/31 14:05
 */

@SpringBootApplication
public class ecaApplication {
    public static void main(String[] args) throws UnknownHostException {
        try {
            ConfigurableApplicationContext application = SpringApplication.run(ecaApplication.class, args);
            Environment env = application.getEnvironment();
            String ip = InetAddress.getLocalHost().getHostAddress();
            String port = env.getProperty("server.port");
            String property = env.getProperty("server.servlet.context-path");
            String path = property == null ? "" : property;
            System.out.println("\n" +
                    "> 核心服务启动\u001b[38;5;50m成功\u001b[0m! 应用程序接口已开放:\n" +
                    "> 本地访问: \thttp://localhost:" + port + path + "/\n" +
                    "> 外部访问: \thttp://" + ip + ":" + port + path + "/\n" +
                    "----------------------------------------------------------------------");
        } catch (Exception e) {
            System.out.println("\n" +
                    "> 核心服务启动\u001b[38;5;196m失败\u001b[0m!\n" +
                    "> 请根据日志输出检查相关配置以及生产环境,本次启动失败可能由下列问题引起:");
            System.out.println(e);
        }

    }
}
